<?php

require_once dirname(__FILE__) . '/../excelapiphp/PHPExcel/IOFactory.php';
require_once dirname(__FILE__) . '/../clases/Constantes.php';

class PeerReview{
	
	private $id;
	private $nombre;
	private $plantilla;
	private $excel; 
	private $path = null;
	
	function PeerReview(){
		
	}
		
	function getNombre(){
		return $this->nombre;
	}
	
	function setNombre($value){
		$this->nombre = $value;
	}
	
	function getPlantilla(){
		return $this->plantilla;
	}
	
	function setPlantilla($value){
		$this->plantilla = $value;
	}
	
	function getId(){
		return $this->id;
	}
	
	function setId($value){
		$this->id = $value; 
	}
	
	function getPath(){
		return $this->path;
	}
	
	function setPath($value){
		$this->path = $value;
	}
		
	function ponerLogoAccenture(){
		
		$objDrawing = new PHPExcel_Worksheet_Drawing();
		$this->excel->setActiveSheetIndex(0);
		$objDrawing->setWorksheet($this->excel->getActiveSheet());
		$objDrawing->setPath(dirname(__FILE__) .'/../imagenes/logoaccenture.png');
		$objDrawing->setCoordinates('G3');
		$objDrawing->setOffsetX(-8);
		$objDrawing->setOffsetY(-7);
		
		$objDrawing = new PHPExcel_Worksheet_Drawing();
		$this->excel->setActiveSheetIndex(2);
		$objDrawing->setWorksheet($this->excel->getActiveSheet());
		$objDrawing->setPath(dirname(__FILE__) .'/../imagenes/logoaccenture.png');
		$objDrawing->setCoordinates('F2');
		$objDrawing->setOffsetX(210);
		$objDrawing->setOffsetY(5);
		
		$objDrawing = new PHPExcel_Worksheet_Drawing();
		$this->excel->setActiveSheetIndex(3);
		$objDrawing->setWorksheet($this->excel->getActiveSheet());
		$objDrawing->setPath(dirname(__FILE__) .'/../imagenes/logoaccenture.png');
		$objDrawing->setCoordinates('F3');
		$objDrawing->setOffsetX(70);
		$objDrawing->setOffsetY(0);
		
	}
	
	function ponerColor(){
		$this->excel->getActiveSheet()->getStyle('C14')->applyFromArray(
				array(
						'fill' => array(
								'type' => PHPExcel_Style_Fill::FILL_SOLID,
								'color' => array('rgb' => Constantes::colorVerdeRGB)
						)
				)
		);
	}
	
	function ponerNumeroRequerimiento($numero){
		$this->excel->setActiveSheetIndex(1)->setCellValue('C10', $numero);
	}
	
	function descargarExcel(){
		
		$file = $this->nombre;
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
		$objWriter->save($file);
		
		
		if (file_exists($file)){
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename='.basename($file));
			header('Cache-Control: max-age=0');
			header('Cache-Control: max-age=1');
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 
			header ('Cache-Control: cache, must-revalidate'); 
			header ('Pragma: public'); 
			header('Content-Length: ' . filesize($file));
			ob_clean();
			flush();
			readfile($file);
		}else{
			exit("No se guardo el archivo" . EOL);
		}
				
	}
	
	
}